package cn.chitanda.weather.ui.CityList

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import cn.chitanda.weather.R
import cn.chitanda.weather.data.place.City
import cn.chitanda.weather.data.weather.Basic
import cn.chitanda.weather.ui.PlaceViewModel
import cn.chitanda.weather.ui.Weather.WeatherViewModel
import kotlinx.android.synthetic.main.citylist_carditem.view.*

class CityListAdapter :
    ListAdapter<Basic, CityListViewHolder>(DiffCallBack) {
    object DiffCallBack : DiffUtil.ItemCallback<Basic>() {
        override fun areItemsTheSame(oldItem: Basic, newItem: Basic): Boolean {
            return oldItem.cid == newItem.cid
        }

        override fun areContentsTheSame(oldItem: Basic, newItem: Basic): Boolean {
            return oldItem == newItem
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CityListViewHolder {
        return CityListViewHolder(
            LayoutInflater.from(parent.context).inflate(
                R.layout.citylist_carditem,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: CityListViewHolder, position: Int) {
        val city=getItem(position)
        holder.itemView.cl_location.text=city.location
       // holder.itemView.cl_tmp.text
    }
}

class CityListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {}